#include <stdio.h>
#define Max_SIZE 10

struct QueueRecord;
typedef struct QueueRecord *Queue;
int IsEmpty( Queue Q );
void MakeEmpty( Queue Q);
int IsFull( Queue Q);
static int Succ( int Value, Queue Q);
void Enqueue( int X, Queue Q);
void Visit( Queue Q);
int Full_Sum;

struct QueueRecord
{
    int Capacity;
    int Front;
    int Rear;
    int Size;
    int *Array;
};

int
IsEmpty( Queue Q )
{
    if( Q -> Size == 0 )
        return 'Y';
    else
        return 'No';
}

void
MakeEmpty( Queue Q)
{
    Q ->Size = 0;
    Q -> Front = 0;
    Q -> Rear = 0;
}

int
IsFull( Queue Q)
{
    if( Q -> Size == Max_SIZE) return 0;
}

static int
Succ( int Value, Queue Q)
{
    if( ++Value == Q -> Capacity)
        Value = 0;
    return Value;
}

//The Enqueue operator
void
Enqueue( int X, Queue Q)
{
    if( IsFull( Q ) == 0) {
        printf("!Error:Full queue\n");
        Full_Sum++;
    }
    else
    {
        Q -> Size++;
        Q -> Rear = Succ( Q -> Rear, Q );
        Q -> Array[ Q -> Rear] = X;
    }
}

void
Visit( Queue Q)
{
    printf("This is the element of Queue:\n");
    for(int j = 0; j < 10;j++)
        printf("%d\n", Q -> Array[j]);
    printf("This is the size of Queue:\n");
    printf("%d\n",Q -> Size);
}

int main(){
    QueueRecord *Q;
    MakeEmpty( Q );
    printf("MakeEmpty successed ? Y/N:\n Answer is:%c\n",IsEmpty( Q ));
    for(int i = 0; i < 13;i++)
        Enqueue( i, Q);
    printf("There is/are %d numbers can't enqueue the queue\n",Full_Sum);
    Visit( Q );
    printf("This is the last place that Front stay:\n");
    printf("At %d of the queue\n", Q -> Front);
    MakeEmpty( Q );
    return 0;
}//程序运行之后出现了诡异的 1702057263
//运行之后 Front的值为 0 说明在QueueFull后 Front已回到起始的第一个位置 且再向队列中增加元素 不会改变Front的位置
//多出几个无法插入的元素，程序就会输出几个Full Queue